#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>

int main(int argc, char ** argv)
{
    pid_t pid;
    char buff[1024];
    int fd;
    int cnt;

    fd = open("testfile",O_RDONLY);
    pid = fork();
    //fd = open("testfile",O_RDONLY);
    if(pid == 0)
    {
        printf("child id is %d -- father id is %d\n",getpid(),getppid());
        cnt = read(fd,buff,10);
        printf("child read buff is %s\n",buff);
    }
    else if(pid > 0)
    {
        printf("father id is %d\n",getpid());
        cnt = read(fd,buff,10);
        printf("father read buff is%s\n",buff);
    }
    else
    {
        perror("fork");
    }

    return 0;
}
